import { deleteByPrimaryKeyForProMenuAuth, selectByPrimaryKeyForProMenuAuth, insertForProMenuAuth, updateForProMenuAuth, deleteByMapForProMenuAuth,updateByMapForProMenuAuth, getOneForProMenuAuth,getAllForProMenuAuth,queryPageForProMenuAuth, countForProMenuAuth, insertBatchForProMenuAuth, deleteBatchForProMenuAuth,updateBatchForProMenuAuth,getPageAuthByMenuTreeId,getAllMenuTreeByAuthID,getProMenuTreeByLevelCode,queryPageForProAuthority,insertForProMenu,updateForProMenu,deleteByPrimaryKeyForProMenu,updateChangeTargetNodeWithSourceNodeForProMenu,deleteByPrimaryKeyForProAuthority,insertForProAuthority,updateForProAuthority,getAllMenuTreeByAuthIDForDeleteTree } from '@/services/system/api_promenuauth';


export default {
    namespace: 'promenuauth',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        menu:{
        	list:[],
        },
        checkedKeys:{
        	list:[]
        },
        checkedKeysByAuth:{
        	list:[]
        },
        recorddata: {
            datarecord:{},
            message:null,
            success: false,
        },
    },

    effects: {
            *delete_by_primarykey_for_promenuauth({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProMenuAuth, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProMenuAuth',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
		                type: 'queryPageForProMenuAuth',
		                payload: responsedata,
                });


            },
            *select_by_primarykey_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProMenuAuth, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProMenuAuth',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(insertForProMenuAuth, payload);
                yield put({
                    type: 'insertForProMenuAuth',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
		                type: 'queryPageForProMenuAuth',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(updateForProMenuAuth, payload);
                yield put({
                    type: 'updateForProMenuAuth',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
		                type: 'queryPageForProMenuAuth',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            *delete_by_map_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProMenuAuth, payload);
                yield put({
                    type: 'deleteByMapForProMenuAuth',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
		                type: 'queryPageForProMenuAuth',
		                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_by_map_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProMenuAuth, payload);
                yield put({
                    type: 'updateByMapForProMenuAuth',
                    payload: response,
                });


                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
                		type: 'queryPageForProMenuAuth',
                		payload: responsedata,
                });

                if (callback) callback();
            },
            *get_one_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProMenuAuth, payload);
                yield put({
                    type: 'getOneForProMenuAuth',
                    payload: response,
                });

                if (callback) callback();
            },
            *get_all_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProMenuAuth, payload);
                yield put({
                    type: 'getAllForProMenuAuth',
                    payload: response,
                });

                if (callback) callback();
            },
            *query_page_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProMenuAuth, payload);
                yield put({
                    type: 'queryPageForProMenuAuth',
                    payload: response,
                });

                if (callback) callback();
            },
            *count_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(countForProMenuAuth, payload);
                yield put({
                    type: 'countForProMenuAuth',
                    payload: response,
                });

                if (callback) callback();
            },
            *insert_batch_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProMenuAuth, payload);
                yield put({
                    type: 'insertBatchForProMenuAuth',
                    payload: response,
                });
                
                const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                
                const responsedata = yield call(queryPageForProAuthority, newPayload);
                yield put({
                	type: 'queryPageForProAuthority',
                	payload: responsedata,
                });
                
                if (callback) callback();
            },
            *delete_batch_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProMenuAuth, payload);
                yield put({
                    type: 'deleteBatchForProMenuAuth',
                    payload: response,
                });

                const responsedata = yield call(queryPageForProMenuAuth, {});
                yield put({
                type: 'queryPageForProMenuAuth',
                payload: responsedata,
                });

                if (callback) callback();
            },
            *update_batch_for_promenuauth({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProMenuAuth, payload);
                yield put({
                    type: 'updateBatchForProMenuAuth',
                    payload: response,
                });
								const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProMenuAuth, newPayload);
                yield put({
	                type: 'queryPageForProMenuAuth',
	                payload: responsedata,
                });

                if (callback) callback();
            },
            *get_page_auth_by_menutreeid({ payload, callback }, { call, put }) {
                const response = yield call(getPageAuthByMenuTreeId, payload);
                yield put({
                    type: 'getPageAuthByMenuTreeId',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_menutree_by_authid({ payload, callback }, { call, put }) {
                const response = yield call(getAllMenuTreeByAuthID, payload);
                yield put({
                    type: 'getAllMenuTreeByAuthID',
                    payload: response,
                });
                if (callback) callback(response);
            },
            *get_promenutree_by_levelcode({ payload, callback }, { call, put }) {
                const response = yield call(getProMenuTreeByLevelCode, payload);
                yield put({
                    type: 'getProMenuTreeByLevelCode',
                    payload: response,
                });
                if (callback) callback(response);
            },
            *insert_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(insertForProMenu, payload);
                yield put({
                    type: 'insertForProMenu',
                    payload: response,
                });
                const newPayload = {
                	parentid: payload.root_parentid,
                };
               
                const responsedata = yield call(getProMenuTreeByLevelCode, newPayload );
                yield put({
                	type: 'getProMenuTreeByLevelCode',
                	payload: responsedata,
                });
                
                const responseAuth = yield call(queryPageForProAuthority, {});
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: responseAuth,
                });
                if (callback) callback();
            },
            *update_for_promenu({ payload, callback }, { call, put }) {
                const response = yield call(updateForProMenu, payload);
                yield put({
                    type: 'updateForProMenu',
                    payload: response,
                });
                
                const newPayload = {
                	parentid: payload.root_parentid,
                };                
                const responsedata = yield call(getProMenuTreeByLevelCode, newPayload );
                yield put({
                	type: 'getProMenuTreeByLevelCode',
                	payload: responsedata,
                });
                
                const responseAuth = yield call(queryPageForProAuthority, {});
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: responseAuth,
                });
                if (callback) callback();
            },
            *delete_by_primary_key_for_promenu({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProMenu, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProMenu',
                    payload: response,
                });
                const newPayload = {
                	parentid: payload.root_parentid,
                };
                const responsedata = yield call(getProMenuTreeByLevelCode, newPayload );
                yield put({
                	type: 'getProMenuTreeByLevelCode',
                	payload: responsedata,
                });
                
                const responseAuth = yield call(queryPageForProAuthority, {});
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: responseAuth,
                });
                if (callback) callback();
            },
            *update_change_target_node_with_source_node_for_pro_menu({ payload, callback }, { call, put }) {
                const response = yield call(updateChangeTargetNodeWithSourceNodeForProMenu, payload);
                yield put({
                    type: 'updateChangeTargetNodeWithSourceNodeForProMenu',
                    payload: response,
                });

                if (callback) callback(response);
            },
            *query_page_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(queryPageForProAuthority, payload);
                yield put({
                    type: 'queryPageForProAuthority',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(insertForProAuthority, payload);

                const responsedata = yield call(queryPageForProAuthority, {});
                yield put({
	                type: 'queryPageForProAuthority',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *update_for_proauthority({ payload, callback }, { call, put }) {
                const response = yield call(updateForProAuthority, payload);

								const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProAuthority, newPayload);
                yield put({
	                type: 'queryPageForProAuthority',
	                payload: responsedata,
                });

                if (callback) callback(response);
            },
            *delete_by_primarykey_for_proauthority({ payload,callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProAuthority, payload);
				
								const newPayload = {currentPage: payload.currentPage,pageSize: payload.pageSize};
                const responsedata = yield call(queryPageForProAuthority, newPayload);
                yield put({
	                type: 'queryPageForProAuthority',
	                payload: responsedata,
                });
								if (callback) callback(response);
            },
            *get_all_menutree_by_authid_for_deletetree({ payload, callback }, { call, put }) {
                const response = yield call(getAllMenuTreeByAuthIDForDeleteTree, payload);
                yield put({
                    type: 'getAllMenuTreeByAuthIDForDeleteTree',
                    payload: response,
                });
                if (callback) callback(response);
            },
    },

    reducers: {
        deleteByPrimaryKeyForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProMenuAuth(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getProMenuTreeByLevelCode(state, action) {
            return {
                ...state,
                menu: action.payload,
            };
        },
        getAllMenuTreeByAuthID(state, action) {
            return {
                ...state,
                checkedKeys: action.payload,
            };
        },
        getPageAuthByMenuTreeId(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProAuthority(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByPrimaryKeyForProMenu(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateChangeTargetNodeWithSourceNodeForProMenu(state, action) {
            return {
                ...state,
                recorddata: action.payload,
            };
        },
        getAllMenuTreeByAuthIDForDeleteTree(state, action) {
            return {
                ...state,
                checkedKeysByAuth: action.payload,
            };
        },
    },
};
